package com.xzs.thinking.elastic.controller;

import com.xzs.thinking.elastic.service.ESSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description
 * @author: Victor.Xiao
 * @create: 2018-08-23 20:08
 **/
@RestController
@RequestMapping("/search")
public class TestController {

    @Autowired
    private ESSearchService esSearchService;

    /**
     * 构建索引
     * @param index
     * @return
     */
    @RequestMapping(value = "/buildIndex")
    @ResponseBody
    public String buildIndex( @RequestParam(value = "index", required = false) String index ) {

        esSearchService.buildIndex(index);
        return "";

    }

    /**
     *  查询数据
     *
     * @param index
     * @param type
     * @param id
     * @return
     */
    @RequestMapping(value = "/data")
    @ResponseBody
    public Map<String, Object> search(
            @RequestParam(value = "index", required = false) String index,
            @RequestParam(value = "type", required = false) String type,
            @RequestParam(value = "id", required = false) String id
    ) {

        //搜索具体的数据来源
        Map<String, Object> returnMap = esSearchService.searchDataByParam("bond2018-03-15", "bond", "AWIoxzdzUfSIA3djz-ZK");
        return returnMap;
    }

}
